
module.exports = function ($scope, $state, $stateParams,$resource,$modal,items,$modalInstance,FileUploader) {
    console.log(items);
    console.log('上面是items')
    $scope.a = {
      'recommend_type_name' : ''
    }
    if(items){
      $scope.a=items;
    }
    $scope.obj = {
      'isSelected' : ''
    }
    $scope.applyarr=[
        {name:'区县项目',value:'0'},
        {name:'市级项目',value:'1'},
    ]
    // 责任处室
    $scope.officeFileArr = [
      {name:'规划发展处',value:'3', id : ['8', '9']},
      {name:'行业管理处  ',value:'6', id : ['3', '4']},
      {name:'人事编制处 ',value:'1', id : ['1', '2']},
      {name:'政策法规处 ',value:'2', id : ['3', '4']},
      {name:'区域合作处',value:'4', id : ['5', '6', '7']},
      {name:'市场开发处 ',value:'5', id : ['1', '2']},
      {name:'产业发展处',value:'7', id : ['8', '9']},
      {name:'特色旅游处',value:'8', id : ['5', '6', '7']},
      {name:'旅游质量监督管理所',value:'9', id : ['3', '4']},
      {name:'旅游产业发展服务中心',value:'10', id : ['8', '9']},
      {name:'机关党委',value:'11', id : ['5', '6', '7']},
      {name:'办公室',value:'12', id : ['5', '6', '7']}
  ]
    // 公告类型
  $scope.typeFileArr = [
      {name:'旅游龙头项目',value:'0', id : '1'},
      {name:'旅游集聚区项目',value:'1', id : '2'},
      {name:'旅游集群项目',value:'2', id : '3'},
      {name:'全域旅游示范区项目',value:'3', id : '4'},
      {name:'特色旅游休闲街区项目',value:'4', id : '5'},
      {name:'特色旅游产业园区项目',value:'5', id : '6'},
      {name:'特色旅游人才培训基地项目',value:'6', id : '7'},
      {name:'特色旅游创客孵化基地项目',value:'7', id : '8'},
      {name:'离境退税项目',value:'8', id : '9'},
      {name:'景区提升工程项目',value:'9', id : '1'},
      {name:'旅游度假区项目',value:'10', id : '2'},
      {name:'乡村旅游项目',value:'11', id : '3'},
      {name:'旅游公共服务体系项目',value:'12', id : '4'},
      {name:'旅游公共交通体系项目',value:'13', id : '5'},
      {name:'旅游智慧化项目',value:'14', id : '6'},
      {name:'旅游节庆活动项目',value:'15', id : '7'},
      {name:'旅游展示活动项目',value:'16', id : '8'},
      {name:'旅游惠民活动项目',value:'17', id : '9'},
      {name:'旅游体制改革项目',value:'18', id : '8'},
      {name:'旅游招徕补贴项目',value:'19', id : '9'},
      {name:'旅游品牌奖励项目',value:'20', id : '1'},
      {name:'宣传营销项目',value:'21', id : '2'},
      {name:'旅游产品研发项目',value:'22', id : '3'},
      {name:'课题调查研究项目',value:'23', id : '4'},
      {name:'区域旅游合作项目',value:'24', id : '5'},
      {name:'旅游招商项目',value:'25', id : '6'},
      {name:'行业管理项目',value:'26', id : '7'},
      {name:'满意度评价项目',value:'27', id : '8'},
      {name:'其他项目',value:'28', id : '9'}     
  ]
    if ($scope.a.recommend_type != undefined){
      for (var i = 0; i < $scope.officeFileArr.length; i++){
        if($scope.a.recommend_type == $scope.officeFileArr[i].value){
            $scope.a.recommend_type_name = $scope.officeFileArr[i].name;
        }
      }
    }
    // 图片
    if ($scope.a.guide_pdf != undefined){
      $scope.imagearr = $scope.a.guide_pdf.split(',');
      for(var i = 0;i<$scope.imagearr.length;i++){
          if($scope.imagearr[i]==''){
              $scope.imagearr.splice(i,1);
          }
      }   
    }
    if ($scope.a.city_project != undefined){
      if($scope.a.city_project == '0'){
        $scope.obj.isSelected = true;
      } else {
        $scope.obj.isSelected = false;
      }
    }
    $scope.image = function(){
				var para = $state.get('app.imageupload');
				//设置上传文件夹，以自己业务命名
				angular.extend(para, {
					resolve : {  
						'dir' : function(){
							return 't1';
						}
					} 
				})
				console.log(para);
				var modalInstance = $modal.open(para);
				modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
					console.log('modal is opened');  
				});  
				modalInstance.result.then(function(result) {  
					console.log(result);  
					$scope.imagearr = result;
					// console.log(scope.imagearr);					
                    // $scope.a.project_file=$scope.imagearr.join(',');
          console.log($scope.imagearr);
          console.log('上面是imagearr')
				}, function(reason) {  
					console.log(reason);// 点击空白区域，总会输出backdrop  
					// click，点击取消，则会暑促cancel  
					$log.info('Modal dismissed at: ' + new Date());  
				}); 
		};

    $scope.del=function(index){
        $scope.imagearr.splice(index,1);
        $scope.a.guide_pdf=$scope.imagearr;
    }
    $scope.change = function(aa){
      // 循环责任处室
      for(var i = 0; i < $scope.officeFileArr.length; i++){
        var arr = $scope.officeFileArr[i].id;
        arr.forEach(element => {
          if(aa == element){
            console.log(arr);
            console.log(i);
            $scope.a.recommend_type_name = $scope.officeFileArr[i].name;
            console.log($scope.a.recommend_type_name);
            $scope.a.recommend_type = $scope.officeFileArr[i].value;
            console.log($scope.a.recommend_type);
          }
        });
      }
    }
    $scope.submit = function(){
        if($scope.obj.isSelected == true){
          $scope.a.city_project = 0;
        } else {
          $scope.a.city_project = 1;
        }
        $scope.a.guide_pdf=$scope.imagearr.join(',');
        $resource('/api/as/ggc/reviewGuide/create', {}, {}).save($scope.a, function(res){
                // console.log(res);
            if(res.errcode === 0){                      
                alert('修改成功');  
                $modalInstance.close();
            }else{
                alert(res.errmsg);
            }
        });
    }
			


};
